#include "CLooseState.h"
#include "CGame.h"
#include "CMainMenuState.h"
#include "CPrintBitmapToScreen.h"
#include "CSpaceStationState.h"

CLooseState::CLooseState(void)
{
	m_nScreenWidth = CGame::GetInstance()->GetScreenWidth();
	m_nScreenHeight = CGame::GetInstance()->GetScreenHeight();
}

CLooseState::CLooseState(const CLooseState&)
{

}

CLooseState::~CLooseState()
{

}

CLooseState& CLooseState::operator=(const CLooseState&)
{
	return *this;
}

CLooseState* CLooseState::GetInstance(void)
{
	static CLooseState instance;
	return &instance;
}

void CLooseState::Enter(void)
{
	m_nCurrentSelection		=  0;
	m_nBackgroundImageID	= -1;
	m_nBackgroundMusicID	= -1;
	m_nMovementSFXID		= -1;
	m_nBitmapFontID			= -1;

	m_fVolume				= CGame::GetInstance()->GetMusicVolume();
	m_fSFXVolume			= CGame::GetInstance()->GetSFXVolume();

	m_nScreenWidth = CGame::GetInstance()->GetScreenWidth();
	m_nScreenHeight = CGame::GetInstance()->GetScreenHeight();
	//isFull = false;
	// Load sounds
	m_nMovementSFXID = CSGD_FModManager::GetInstance()->LoadSound("resource/Sound/SGP_MenuSelection.wav");
	m_nBackgroundMusicID = CSGD_FModManager::GetInstance()->LoadSound("resource/Sound/SGP_Course.mp3");

	// Load textures
	m_nBackgroundImageID = CSGD_TextureManager::GetInstance()->LoadTexture("Resource/Graphics/Art Assets/SGP_CSBackground.png");

}
bool CLooseState::Input(void)
{
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_LEFT) || CSGD_DirectInput::GetInstance()->JoystickGetLStickDirPressed(DIR_LEFT))
	{
		if(m_nCurrentSelection > 0)
			--m_nCurrentSelection;
		else
			m_nCurrentSelection = 2;

		CSGD_FModManager::GetInstance()->PlaySoundA(m_nMovementSFXID);
	}

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RIGHT) || CSGD_DirectInput::GetInstance()->JoystickGetLStickDirPressed(DIR_RIGHT))
	{
		if(m_nCurrentSelection < 2)
			++m_nCurrentSelection;
		else
			m_nCurrentSelection = 0;

		CSGD_FModManager::GetInstance()->PlaySoundA(m_nMovementSFXID);
	}
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)|| CSGD_DirectInput::GetInstance()->JoystickButtonPressed(0))
	{
		if(m_nCurrentSelection ==0)
		{
			CGame::GetInstance()->ChangeState(CSpaceStationState::GetInstance(), true);
		}
		if(m_nCurrentSelection == 1)
		{
			CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
		}
		if(m_nCurrentSelection == 2)
		{
			// Exit
			return false;
		}
	}
	return true;
}
void CLooseState::Update(float fElapsedTime)
{

}
void CLooseState::Render(void)
{
	CSGD_TextureManager::GetInstance()->Draw(m_nBackgroundImageID, 0, 0, 0.67f, 0.6f);

	if(m_nCurrentSelection == 0)
		CPrintBitmapFontToScreen::GetInstance()->Print("BACK TO SPACE STATION", 150, 350, 1.0f, D3DCOLOR_XRGB(0,255,0));
	else
		CPrintBitmapFontToScreen::GetInstance()->Print("BACK TO SPACE STATION", 150, 350, 1.0f, D3DCOLOR_XRGB(255,255,0));

	if(m_nCurrentSelection == 1)
		CPrintBitmapFontToScreen::GetInstance()->Print("BACK TO MAIN", 350, 400, 1.0f, D3DCOLOR_XRGB(0,255,0));
	else
		CPrintBitmapFontToScreen::GetInstance()->Print("BACK TO MAIN", 350, 400, 1.0f, D3DCOLOR_XRGB(255,255,0));

	if(m_nCurrentSelection == 2)
		CPrintBitmapFontToScreen::GetInstance()->Print("EXIT", 100, 400,1.0f, D3DCOLOR_XRGB(0,255,0));
	else
		CPrintBitmapFontToScreen::GetInstance()->Print("EXIT", 100, 400,1.0f, D3DCOLOR_XRGB(255,255,0));


	CPrintBitmapFontToScreen::GetInstance()->Print("YOU LOSE", 150, 50, 3.0f, D3DCOLOR_XRGB(255,0,0));

}
void CLooseState::Exit(void)
{

}